/**
 * 
 */
package cn.haona.game.simb.object;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.haona.game.simb.object.bio.Human;
import cn.haona.game.simb.object.bio.Npc;
import cn.haona.game.simb.object.department.HAB;
import cn.haona.game.simb.object.god.MainManager;

/**
 * 团队
 * 
 * @author shenhao
 * 
 */
public abstract class TeamImpl extends CellImpl implements Serializable
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7059485799899838614L;

	/**
	 * 带头玩家
	 * 
	 * @return
	 */
	public static Long getUserLeaderID(Long sponsor)
	{
		// 民政局
		HAB hab = MainManager.getInstance().getEntityManager().getHab();
		Long lLeader = hab.randomFindUserIDs(1, new Long[]
		{ sponsor }).get(0);
		return lLeader;
	}

	/**
	 * 得到玩家团队
	 * 
	 * @param leaderID
	 *            暂时没用
	 * @param num
	 * @return
	 */
	public static List<Long> getUserMembers(Long sponsor, Long leaderID, int num)
	{
		// 民政局
		HAB hab = MainManager.getInstance().getEntityManager().getHab();
		return hab.randomFindUserIDs(num, new Long[]
		{ leaderID, sponsor });
	}

	/**
	 * 得到一个带头的NPC
	 * 
	 * @param jobs
	 *            带头人可以是的工作
	 * @param exceptJobs
	 *            带头人不能是的工作
	 * @return
	 */
	public static Long getNpcLeaderID(int[] jobs, int[] exceptJobs)
	{
		// 民政局
		HAB hab = MainManager.getInstance().getEntityManager().getHab();
		Long lLeader = hab.randomFindNpcIDs(1, jobs, exceptJobs, null).get(0);
		return lLeader;
	}

	/**
	 * 得到NPC队员
	 * 
	 * @param leaderID
	 *            领导ID 如果是-1那么没有领导
	 * @param num
	 *            队员个数
	 * @return
	 */
	public static List<Long> getNpcMembers(Long leaderID, int num)
	{
		// 队员
		List<Long> listMember = null;

		// 民政局
		HAB hab = MainManager.getInstance().getEntityManager().getHab();
		// 领导的工作
		int iLeaderJob = Human.JOB_ROGUE_LEVEL_2;

		// 如果有领导
		if (leaderID != -1)
		{
			try
			{
				// 找到领导
				Npc npc = (Npc) MainManager.getInstance().getEntityManager().getCellInstance(Npc.class.getName(),
						leaderID);
				// 搞到他的工作
				iLeaderJob = npc.getNpcPO().getJob();
			}
			catch (Exception e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		// 如果没有领导
		if (leaderID == -1)
		{
			// 随便
			listMember = hab.randomFindNpcIDs(num, null, null, null);
		}
		else
		{
			// 流氓-0
			if (iLeaderJob == Human.JOB_ROGUE_LEVEL_0)
			{
				// 流氓-0、百姓
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_ROGUE_LEVEL_0, Human.JOB_CITIZEN_0 }, null, new Long[]
				{ leaderID });
			}
			// 流氓-1
			else if (iLeaderJob == Human.JOB_ROGUE_LEVEL_1)
			{
				// 流氓-0、百姓
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_ROGUE_LEVEL_0, Human.JOB_CITIZEN_0 }, null, new Long[]
				{ leaderID });
			}
			// 流氓-2
			else if (iLeaderJob == Human.JOB_ROGUE_LEVEL_2)
			{
				// 流氓-0、流氓-1、百姓
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_ROGUE_LEVEL_0, Human.JOB_ROGUE_LEVEL_1, Human.JOB_ROGUE_LEVEL_0, Human.JOB_CITIZEN_0 },
						null, new Long[]
						{ leaderID });
			}
			// 警察-0
			else if (iLeaderJob == Human.JOB_POLICE_LEVEL_0)
			{
				// 警察-0 流氓-1、流氓-0、百姓
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_POLICE_LEVEL_0, Human.JOB_ROGUE_LEVEL_1, Human.JOB_ROGUE_LEVEL_0, Human.JOB_CITIZEN_0 },
						null, new Long[]
						{ leaderID });
			}
			// 警察-1
			else if (iLeaderJob == Human.JOB_POLICE_LEVEL_1)
			{
				// 警察-0 流氓-2、流氓-1、百姓-0
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_POLICE_LEVEL_0, Human.JOB_ROGUE_LEVEL_2, Human.JOB_ROGUE_LEVEL_1, Human.JOB_CITIZEN_0 },
						null, new Long[]
						{ leaderID });
			}
			// 武警-0
			else if (iLeaderJob == Human.JOB_FORCE_POLICE_LEVEL_0)
			{
				// 武警-0、百姓-0
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_FORCE_POLICE_LEVEL_0, Human.JOB_CITIZEN_0 }, null, new Long[]
				{ leaderID });

			}
			// 保镖-0
			else if (iLeaderJob == Human.JOB_BODYGUARD_LEVEL_0)
			{
				// 警察-0 流氓-2、流氓-1、百姓
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_POLICE_LEVEL_0, Human.JOB_ROGUE_LEVEL_2, Human.JOB_ROGUE_LEVEL_1 }, null, new Long[]
				{ leaderID });

			}
			// 地产商-0
			else if (iLeaderJob == Human.JOB_ESTATE_LEVEL_0)
			{
				// 警察-1 、保镖-0 流氓-2
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_POLICE_LEVEL_1, Human.JOB_BODYGUARD_LEVEL_0, Human.JOB_ROGUE_LEVEL_2 }, null, new Long[]
				{ leaderID });

			}
			// 腐败官员-0
			else if (iLeaderJob == Human.JOB_DIRTY_OFFICER_0)
			{
				// 警察-1 、保镖-0、武警
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_POLICE_LEVEL_1, Human.JOB_BODYGUARD_LEVEL_0, Human.JOB_FORCE_POLICE_LEVEL_0 }, null,
						new Long[]
						{ leaderID });
			}
			// 公民-0
			else if (iLeaderJob == Human.JOB_CITIZEN_0)
			{
				// 公民
				listMember = hab.randomFindNpcIDs(num, new int[]
				{ Human.JOB_CITIZEN_0 }, null, new Long[]
				{ leaderID });
			}
			else
			{
				listMember = new ArrayList<Long>();
			}
		}

		return listMember;
	}

}
